﻿define(['jquery', 'knockout', 'jqueryUi'],
    function ($, ko) {
        "use strict";

        ko.bindingHandlers.dragMove = {
            init: function(element, valueAccessor, allBindings){
                var accessor = valueAccessor();
                $(element).draggable({
                    stop: function( event, ui ) {
                        accessor.top(Math.round(ui.position.top));
                        accessor.left(Math.round(ui.position.left));
                    }
                }).draggable( "disable" );
            },
            update: function (element, valueAccessor) {
                var accessor = valueAccessor();
                if(ko.unwrap(accessor.draggable) !== true){
                    $(element).draggable( "disable" );
                    return;
                }
                $(element).draggable( "enable" );
            }
        };
    });